package bud.mobile.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 클라이언트가 member 관련 request 를 보내면 로그인 여부를 확인 후, 
 * 로그인이 되지 않았다면 로그인 페이지로 방향 유도
 * @author Administrator
 *
 */
public class LoginChecker implements Filter{

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain chain) throws IOException, ServletException {
		
		HttpServletRequest request = (HttpServletRequest)arg0;
		HttpServletResponse response = (HttpServletResponse)arg1;
		Object obj = request.getSession().getAttribute("memberSession");
		if(obj == null){
			response.sendRedirect(request.getContextPath() + "/login.mo");
		} else {
			chain.doFilter(arg0, arg1);
		}
		
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
